import React from "react";
import { Button, message, Popconfirm } from "antd";
import { DeleteOutlined } from "@ant-design/icons";

export default (removeFunc, record, actionRef, params) => {
  const handleRemove = async (row) => {
    const postData = params?.ids || [row.id]; // 传了params则取，不传取默认的
    const res = await removeFunc(postData);
    if (res.code === 200) {
      message.success("删除成功");
      actionRef?.current.reload();
    }
  };

  return (
    <Popconfirm
      key="remove"
      title="确定删除?"
      onConfirm={() => handleRemove(record)}
    >
      <Button className="my-delete-btn"  type={record ? "text" : "default"} danger={!record}>
        {!record && <DeleteOutlined />}
        删除
      </Button>
    </Popconfirm>
  );
};
